package com.ltxtiyu.video.api;

import com.alibaba.dubbo.config.annotation.Reference;
import com.ltxtiyu.video.common.DataGridParam;
import com.ltxtiyu.video.common.SecurityConstant;
import com.ltxtiyu.video.entity.TokenStore;
import com.ltxtiyu.video.entity.User;
import com.ltxtiyu.video.service.app.MomentService;
import com.ltxtiyu.video.service.app.TokenStoreService;
import com.ltxtiyu.video.service.app.UserService;
import com.ltxtiyu.video.tool.ParamTool;
import com.ltxtiyu.video.tool.Tool;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@RestController
@RequestMapping("/apiMoment")
public class ApiMoment {
    @Reference
    MomentService momentService;

    /**
     * 动态详情
     * @param request
     * @return
     */
    @RequestMapping("/singleMoment")
    public String singleMoment(HttpServletRequest request){
        Map<String, String> map = ParamTool.requestToParamMap(request);
        map.put("userId",String.valueOf(-1)); // 默认用户没有登陆是-1
        return momentService.singleMoment(map);
    }

    /**
     * 动态详情
     * @param request
     * @return
     */
    @RequestMapping("/listMomentForPerson")
    public String listMomentForPerson(HttpServletRequest request){
        Map<String, String> params = ParamTool.requestToParamMap(request);
        DataGridParam dgp = Tool.genDataGridParam(request);
        Integer start = (dgp.getPage() - 1) * dgp.getRows();
        Integer rows = dgp.getRows();
        params.put("start", String.valueOf(start));
        params.put("rows", String.valueOf(rows));
        params.put("userId",String.valueOf(-1)); // 默认用户没有登陆是-1
        return momentService.listMomentForPerson(params);
    }


}
